home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2839 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  48 lines

  1. Path: news.nevada.edu!chancl
  2. From: chancl@nevada.edu (Clapton Chan)
  3. Newsgroups: comp.lang.c
  4. Subject: why get 9 strings only?
  5. Date: 24 Jan 1996 10:33:21 GMT
  6. Organization: University of Nevada System Computing Services
  7. Message-ID: <4e51th$4bi@news.nevada.edu>
  8. NNTP-Posting-Host: unauthenticated_user@pioneer.nevada.edu
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. I can't figure out why I can only input 9 strings
  12. instead of 10 on the following program:
  13.  
  14. **************************************************************
  15.  
  16. /* Write a program that reads a number and then a list of  */
  17. /* strings (all on separate lines), and then prints one of */ 
  18. /* the lines from the list as selected by the number.      */
  19.  
  20. #include <stdio.h>
  21.  
  22. void main()
  23. {
  24.     char str[10][80];
  25.     int i, j;
  26.  
  27.     printf("Enter a number (0-9):\n");
  28.     scanf("%d", &j);
  29.  
  30.     printf("Enter 10 strings:\n");
  31.     for(i=0; i<10; i++)         /* get 10 strings */
  32.         gets(str[i]);        /* but can input 9 strings */
  33.  
  34.     if(j>0 && j<10)
  35.         printf("Answer: %s\n", str[j]);
  36. }
  37.  
  38. **********************************************************
  39.  
  40. I have debugged it and find the when "i" comes to
  41. "gets(str[i])", "i" bumps up to two before accepting
  42. the first input string.  Why?
  43.  
  44. Please email me any hint.  Thanks in advance.
  45.  
  46. Cheers,
  47. Clapton
  48.